import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getParameter")
public class GetParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //预期浏览器会发一个 /getParameter?studentId=10&classId=20 请求
        //借助 req 里的 getParameter 方法就能拿到 query string 中的键值对内容了
        String studentId = req.getParameter("studentId");
        String classId = req.getParameter("classId");
        //resp.getWriter().write("stduentId = "+studentId + " classId = " + classId);
        //响应的时候可以设置编码格式
        //此时设置字符集,必须要在 write 的上面
/*        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf8");*/
        //也可以一起写
        resp.setContentType("text/html; charset=utf8");
        resp.getWriter().write("学号 = "+studentId + " 班级 = " + classId);

    }
}
